package com.ruoyi.mes.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.mes.domain.NewEnergyEfficiency;
import com.ruoyi.mes.service.INewEnergyEfficiencyService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 设备能效KPIController
 * 
 * @author ruoyi
 * @date 2025-05-14
 */
@RestController
@RequestMapping("/mes/energyEfficiency")
public class NewEnergyEfficiencyController extends BaseController
{
    @Autowired
    private INewEnergyEfficiencyService newEnergyEfficiencyService;

    /**
     * 查询设备能效KPI列表
     */
    @PreAuthorize("@ss.hasPermi('mes:energyEfficiency:list')")
    @GetMapping("/list")
    public TableDataInfo list(NewEnergyEfficiency newEnergyEfficiency)
    {
        startPage();
        List<NewEnergyEfficiency> list = newEnergyEfficiencyService.selectNewEnergyEfficiencyList(newEnergyEfficiency);
        return getDataTable(list);
    }

    /**
     * 导出设备能效KPI列表
     */
    @PreAuthorize("@ss.hasPermi('mes:energyEfficiency:export')")
    @Log(title = "设备能效KPI", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NewEnergyEfficiency newEnergyEfficiency)
    {
        List<NewEnergyEfficiency> list = newEnergyEfficiencyService.selectNewEnergyEfficiencyList(newEnergyEfficiency);
        ExcelUtil<NewEnergyEfficiency> util = new ExcelUtil<NewEnergyEfficiency>(NewEnergyEfficiency.class);
        util.exportExcel(response, list, "设备能效KPI数据");
    }

    /**
     * 获取设备能效KPI详细信息
     */
    @PreAuthorize("@ss.hasPermi('mes:energyEfficiency:query')")
    @GetMapping(value = "/{kpiId}")
    public AjaxResult getInfo(@PathVariable("kpiId") Long kpiId)
    {
        return success(newEnergyEfficiencyService.selectNewEnergyEfficiencyByKpiId(kpiId));
    }

    /**
     * 新增设备能效KPI
     */
    @PreAuthorize("@ss.hasPermi('mes:energyEfficiency:add')")
    @Log(title = "设备能效KPI", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NewEnergyEfficiency newEnergyEfficiency)
    {
        return toAjax(newEnergyEfficiencyService.insertNewEnergyEfficiency(newEnergyEfficiency));
    }

    /**
     * 修改设备能效KPI
     */
    @PreAuthorize("@ss.hasPermi('mes:energyEfficiency:edit')")
    @Log(title = "设备能效KPI", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NewEnergyEfficiency newEnergyEfficiency)
    {
        return toAjax(newEnergyEfficiencyService.updateNewEnergyEfficiency(newEnergyEfficiency));
    }

    /**
     * 删除设备能效KPI
     */
    @PreAuthorize("@ss.hasPermi('mes:energyEfficiency:remove')")
    @Log(title = "设备能效KPI", businessType = BusinessType.DELETE)
	@DeleteMapping("/{kpiIds}")
    public AjaxResult remove(@PathVariable Long[] kpiIds)
    {
        return toAjax(newEnergyEfficiencyService.deleteNewEnergyEfficiencyByKpiIds(kpiIds));
    }
}
